package libRender;

import engine.render.type.Tri;
import engine.res.Bitmap;
import engine.res.Color;

public class Box 
{
    
    private static Box singleton;
    
    public static Box gen() 
    {
        if (singleton == null) 
        {
            singleton = new Box();
        }
        return singleton;
    }
    
    private Box() 
    {
    }
    
    public Tri[] get(
            float x, float y, float z, 
            float sizeX, float sizeY, float sizeZ, 
            Color modifier, 
            Bitmap tex) 
    {
        float radX = 0.5f * sizeX;
        float radY = 0.5f * sizeY;
        float radZ = 0.5f * sizeZ;
        Tri[] zl = Quad.gen().getGenericXY(x, y, z - radZ, sizeX, sizeY, false, modifier, tex);
        Tri[] zr = Quad.gen().getGenericXY(x, y, z + radZ, sizeX, sizeY, true, modifier, tex);
        Tri[] yl = Quad.gen().getGenericXZ(x, y - radY, z, sizeX, sizeZ, false, modifier, tex);
        Tri[] yr = Quad.gen().getGenericXZ(x, y + radY, z, sizeX, sizeZ, true, modifier, tex);
        Tri[] xl = Quad.gen().getGenericYZ(x - radX, y, z, sizeY, sizeZ, false, modifier, tex);
        Tri[] xr = Quad.gen().getGenericYZ(x + radX, y, z, sizeY, sizeZ, true, modifier, tex);
        Tri[] result = new Tri[] {
            zl[0], zl[1], 
            zr[0], zr[1], 
            yl[0], yl[1], 
            yr[0], yr[1], 
            xl[0], xl[1], 
            xr[0], xr[1], 
        };
        return result;
    }
    
    public Tri[] getInverted(
            float x, float y, float z, 
            float sizeX, float sizeY, float sizeZ, 
            Color modifier, 
            Bitmap tex) 
    {
        float radX = 0.5f * sizeX;
        float radY = 0.5f * sizeY;
        float radZ = 0.5f * sizeZ;
        Tri[] zl = Quad.gen().getGenericXY(x, y, z - radZ, sizeX, sizeY, true, modifier, tex);
        Tri[] zr = Quad.gen().getGenericXY(x, y, z + radZ, sizeX, sizeY, false, modifier, tex);
        Tri[] yl = Quad.gen().getGenericXZ(x, y - radY, z, sizeX, sizeZ, true, modifier, tex);
        Tri[] yr = Quad.gen().getGenericXZ(x, y + radY, z, sizeX, sizeZ, false, modifier, tex);
        Tri[] xl = Quad.gen().getGenericYZ(x - radX, y, z, sizeY, sizeZ, true, modifier, tex);
        Tri[] xr = Quad.gen().getGenericYZ(x + radX, y, z, sizeY, sizeZ, false, modifier, tex);
        Tri[] result = new Tri[] {
            zl[0], zl[1], 
            zr[0], zr[1], 
            yl[0], yl[1], 
            yr[0], yr[1], 
            xl[0], xl[1], 
            xr[0], xr[1], 
        };
        return result;
    }
    
}
